package com.zhiwang.xiaoqu

import android.app.Activity
import android.app.Application
import android.content.Context
import androidx.multidex.MultiDex
import com.liulishuo.filedownloader.FileDownloader
import com.zhiwang.xiaoqu.di.AndroidInjectorHelper
import com.zhiwang.xiaoqu.di.component.AppComponent
import com.zhiwang.xiaoqu.di.component.DaggerAppComponent
import com.zhiwang.xiaoqu.di.module.AppModule
import com.zhiwang.xiaoqu.mvp.model.sharepref.PrefManager
import com.zhiwang.xiaoqu.viewmodel.NetWorkViewModel
import com.zhiwang.xiaoqu.widget.Toasty
import dagger.android.AndroidInjector
import dagger.android.DispatchingAndroidInjector
import dagger.android.HasActivityInjector
import javax.inject.Inject


class App : Application(), HasActivityInjector {


    lateinit var appComponent: AppComponent


    @Inject
    lateinit var dispatchingAndroidInjector: DispatchingAndroidInjector<Activity>

    @Inject
    lateinit var networkViewModel: NetWorkViewModel

    override fun activityInjector(): AndroidInjector<Activity> = dispatchingAndroidInjector


    override fun onCreate() {
        super.onCreate()
        appComponent = DaggerAppComponent.builder()
            .appModule(AppModule(this))
            .build()
        appComponent.inject(this)
        //统一管理注入
        AndroidInjectorHelper.setUp(this)
        //FileDownLoader 下载初始化
        FileDownloader.setup(this)

        PrefManager.init(this)

        Toasty.init(this)
    }

    override fun attachBaseContext(base: Context?) {
        super.attachBaseContext(base)
        MultiDex.install(this)
    }
}